#include "pch.h"
#include "Shader.h"

Shader::Shader(GLuint type)
{
	Id = glCreateShader(type);
}

Shader::~Shader()
{
	glDeleteShader(Id);
}

bool Shader::GetStatus() const
{
	GLint Result = GL_FALSE;

	glGetShaderiv(Id, GL_COMPILE_STATUS, &Result);

	return Result == GL_TRUE;
}

const char * Shader::GetStatusMessage()
{
	GLint InfoLength = 0;
	glGetShaderiv(Id, GL_INFO_LOG_LENGTH, &InfoLength);

	if (InfoLength > 0)
	{
		ErrorMsg.resize(static_cast<unsigned int>(InfoLength + 1ULL));
		ErrorMsg[0] = 0;
		glGetShaderInfoLog(Id, static_cast<GLsizei>(InfoLength), NULL, &ErrorMsg[0]);

		return &ErrorMsg[0];
	}

	return "";
}

void Shader::Bind()
{
	glCompileShader(Id);
}

void Shader::Unbind()
{
	// nothing to be done
}

void Shader::SetSource(const char * src)
{
	glShaderSource(Id, 1, &src, NULL);
	Bind();
}
